package com.xbongbong.paas.factory;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.handle.*;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
 * web端解析数据工厂类
 * @author 吴峰
 * @version v1.0
 * @date 2020/3/24 16:18
 * @since v1.0
 */

@Component
public class WebDataAnalysisFactory {


    private final static Map<Integer, AbstractWebDataAnalysisHandle> WEB_DATA_ANALYSIS_HANDLE_MAP = new ConcurrentHashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);

    @Resource
    private CustomerAnalysisDataHandle customerAnalysisDataHandle;
    @Resource
    private ContractAnalysisDataHandle contractAnalysisDataHandle;
    @Resource
    private ProductAnalysisDataHandle productAnalysisDataHandle;
    @Resource
    private DistributorAnalysisDataHandle distributorAnalysisDataHandle;
    @Resource
    private DistributorContactAnalysisDataHandle distributorContactAnalysisDataHandle;
    @Resource
    private DistributorCommunicateAnalysisDataHandle distributorCommunicateAnalysisDataHandle;
    @Resource
    private OrderAnalysisDataHandle orderAnalysisDataHandle;
    @Resource
    private ReturnAnalysisDataHandle returnAnalysisDataHandle;
    @Resource
    private DistributorAccountAnalysisDataHandle distributorAccountAnalysisDataHandle;
    @Resource
    private CompetitorAnalysisDataHandle competitorAnalysisDataHandle;


    @PostConstruct
    public void init() {
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), customerAnalysisDataHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.CONTRACT.getCode(), contractAnalysisDataHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.PRODUCT.getCode(), productAnalysisDataHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.DISTRIBUTOR_MANAGEMENT.getCode(), distributorAnalysisDataHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.DISTRIBUTOR_CONTACT.getCode(), distributorContactAnalysisDataHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.DISTRIBUTOR_COMMUNICATE.getCode(), distributorCommunicateAnalysisDataHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.ORDER.getCode(), orderAnalysisDataHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.RETURN.getCode(), returnAnalysisDataHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getCode(), distributorAccountAnalysisDataHandle);
        WEB_DATA_ANALYSIS_HANDLE_MAP.put(XbbRefTypeEnum.COMPETITOR.getCode(),competitorAnalysisDataHandle);
    }

    public AbstractWebDataAnalysisHandle getByBusinessType(Integer businessType, Integer saasMark) {
        if (Objects.equals(SaasMarkEnum.SAAS.getCode(), saasMark)) {
            return WEB_DATA_ANALYSIS_HANDLE_MAP.get(businessType);
        }
        return null;
    }

}
